package com.njust.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * 集中处理所有异常
 *
 * 1、集中处理所有异常的类加入到ioc容器中
 * 2、@ControllerAdvice专门处理异常的类
 */
@ControllerAdvice
public class GlobalException {

    @ExceptionHandler(value = { ArithmeticException.class })
    public ModelAndView handleException01(Exception exception) {
        System.out.println("全局的：handleException01..." + exception);
        //
        ModelAndView view = new ModelAndView("error.jsp");
        view.addObject("ex", exception);
        // 视图解析器拼串
        return view;
    }
}
